mod common;

use common::{dourl, eq_obj_notime};
use serde_json::json;
use std::{file, line};

#[tokio::test]
async fn e_chunk() {
    let data = json!({
        "n": "chunk5"
    });
    let ret = dourl(&data, "rmtab").await.expect("error_1");
    assert_eq!(ret, json!({"code": 1000, "fail": false, "success": true}));

    let data = json!({
        "tab": "chunk5",
        "rmempty": true,
        "line": "line-one",
        "data": [
            {
                "psn": "p1001 ",
                "wsn": "w001",
                "v": {
                    "d1":0,
                    "d2":0.0,
                    "d3":21,
                    "d4":"",
                    "d5":"  ",
                    "d6":"0",
                    "d7":"000",
                    "d8":"0.00",
                }
            }
        ]
    });
    let ret = dourl(&data, "chunk").await.expect("error_3");
    assert_eq!(ret, json!({"code": 1000, "fail": false, "success": true}));

    let data = json!({
        "n": "chunk5",
        "obj": "*",
        "opt": {"and": [
            {"eq": "psn", "v": "p1001 "}
        ]}
    });
    let mut ret = dourl(&data, "get").await.expect("error_4");
    eq_obj_notime(
        &mut ret,
        json!({
            "code": 100,
            "fail": false,
            "success": true,
            "data": {
                "chunk5": {
                    "data": [{"d3": 21, "line": "line-one", "psn": "p1001 ", "wsn": "w001", "dtp": 0}]
                }
            }
        }),
        line!(),
        file!(),
    );
}
